#include "glscanprogram.h"

glscanprogram::glscanprogram(const QString &vertex, const QString &fragment, QObject *parent)
    : QOpenGLShaderProgram(parent), renderData(nullptr)
{
    vShader = new QOpenGLShader(QOpenGLShader::Vertex, this);
    fShader = new QOpenGLShader(QOpenGLShader::Fragment, this);
    vShader->compileSourceFile(vertex);
    fShader->compileSourceFile(fragment);
    this->addShader(vShader);
    this->addShader(fShader);
    this->link();
}

glscanprogram::~glscanprogram()
{
    locationHash.clear();
}

void glscanprogram::setLocation()
{
    int temp = 0;
    temp = this->attributeLocation("pos");
    locationHash.insert("pos", temp);
    temp = this->uniformLocation("currentColor");
    locationHash.insert("currentColor", temp);
}

int glscanprogram::getLocation(const QString &key)
{
    return locationHash.value(key);
}

int glscanprogram::getScanVertexSize()
{
    return 10000;
}

const GLfloat *glscanprogram::getScanVertexData()
{
    if (!renderData) {
        renderData = GLServer::getInstance()->getScanVertexData();
    }
    return renderData;
}
